<?php

namespace App\Jobs\RemoveDelCatalogData;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;


class UpdateCatalogTable implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $bookTitleList;
    protected $catalogTable;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($bookTitleList, $catalogTable)
    {
        $this->bookTitleList = $bookTitleList;
        $this->catalogTable  = $catalogTable;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $bookTitleList = $this->bookTitleList;
        $catalogTable  = $this->catalogTable;
        foreach ($bookTitleList as $val2) {
            DB::table($catalogTable)->where('book_title_id', $val2->pre_id)->update(['book_title_id' => $val2->id]);
        }
    }

}
